<template>
  <div class="map-container">
    <!-- <div class="menu">
      <el-switch
        v-model="traffic"
        inline-prompt
        active-text="路况"
        inactive-text="路况"
      />
      <div class="menu-item">
        <img src="/src/assets/images/消息.png" alt="" />
      </div>
      <div class="menu-item">
        <img src="/src/assets/images/交通上报.png" alt="" />
      </div>
      <div class="menu-item">
        <img src="/src/assets/images/用户.png" alt="" />
      </div>
    </div> -->
    <!-- 工具箱 -->
    <MapTools />
    <!-- 切底图 -->
    <div class="change-base-map">
      <img
        src="/src/assets/images/vec.png"
        :class="currentBaseMap == 'vec' ? 'currentBaseMap' : ''"
        @click="changeBaseMap('vec')"
      />
      <img
        src="/src/assets/images/img.png"
        :class="currentBaseMap == 'img' ? 'currentBaseMap' : ''"
        @click="changeBaseMap('img')"
      />
    </div>
    <!-- 地图 -->
    <div id="map">
      <!-- 鼠标位置控件 -->
      <div id="mouse-position"></div>
      <!-- 弹窗 -->
      <div id="popup-monitor" class="ol-popup"></div>
      <div id="popup" class="ol-popup"></div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { initMap } from './hooks/initMap' // 初始化地图
import MapTools from './mapTools.vue'

// import { FlyTo } from './hooks/flyTo'
// import trafficApi from 'apis/traffic.js'
const { map } = initMap() // 初始化地图
const currentBaseMap = ref('vec') // 底图切换

const traffic = ref(false)
/*------------- 底图切换 --------------*/
function changeBaseMap(name) {
  if (name == currentBaseMap.value) return
  currentBaseMap.value = name
  switch (name) {
    case 'vec':
      map.value.getLayers().getArray()[0].setVisible(true)
      map.value.getLayers().getArray()[1].setVisible(false)
      break
    case 'img':
      map.value.getLayers().getArray()[0].setVisible(false)
      map.value.getLayers().getArray()[1].setVisible(true)
      break
  }
}
// nextTick(() => {})
</script>

<!-- 控件 -->
<style>
/* 导航控件 */
/* .ol-zoom {
  right: 0.5em;
} */
/* 缩放控件 */
.ol-zoomslider {
  top: 7.5em;
}
.ol-zoomslider {
  top: 7.5em;
  background: rgba(0, 0, 0, 0.2);
  transition: all 0.2s;
}
.ol-zoomslider:hover {
  background: rgba(0, 0, 0, 0.3);
}
/*=E 自定义鹰眼样式 */
/* 切换 */
</style>

<style scoped>
.map-container {
  position: relative;
  width: 100%;
  /* height: 100%; */
  height: calc(100% - 58px);
}
#map {
  width: 100%;
  height: 100%;
}
/*------------- 菜单 --------------*/
.menu {
  position: absolute;
  top: 35px;
  right: 5px;
  z-index: 3;
}
.menu .menu-item {
  background: rgba(242, 165, 0, 0.5);
  margin: 10px;
  border-radius: 3px;
}
.menu .menu-item img {
  /* width: 22px; */
  /* height: 22px; */
}
/*------------- 底图切换 --------------*/

.change-base-map {
  position: absolute;
  bottom: 5px;
  right: 0;
  z-index: 3;
}
.change-base-map img {
  width: 70px;
  height: 45px;
  margin: 5px;
  border-radius: 5px;
  transition: all 0.5s;
}
/* 当前 */
img.currentBaseMap {
  box-shadow: 0px 0px 3px 3px #3a8fe2;
}
</style>
